home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1994 November / Cd Ware (Nro. 2) - Epimundo.iso / DOS / PG / COMBOX.ZIP / ENUMSTRS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-03-28  |  3.4 KB  |  123 lines

  1. Unit EnumStrs;
  2.  
  3. { enumerator field strings }
  4.  
  5. Interface
  6.  
  7. uses
  8.    Global, Objects;
  9.  
  10. { add enumerator id's here }
  11. { and the actual strings at the end of this file }
  12. type
  13.    TEnumId = ( enSmoker, enSex, enProvince );
  14.  
  15. type
  16.    PEnumerator = ^TEnumerator;
  17.    TEnumerator = object ( TCollection )
  18.       MaxLen : word;
  19.       Constructor Init ( NumItems : byte );
  20.       Procedure CalcMaxLen;
  21.       end;
  22.  
  23. var
  24.    Enumerator : array [ TEnumId ] of PEnumerator;
  25.  
  26. Function SmokerStr ( Status : TSmoker ) : string;
  27. Function SexStr ( Sex : TSex ) : string;
  28. Function ProvinceStr ( Province : TProvince ) : string;
  29.  
  30. Implementation
  31.  
  32. {========================================================================}
  33. { Enumerator Collection object                                           }
  34. {========================================================================}
  35.  
  36. Constructor TEnumerator.Init ( NumItems : byte );
  37.  
  38. Begin
  39.    inherited Init ( NumItems, 0 );
  40. End;
  41.  
  42. {========================================================================}
  43.  
  44. Procedure TEnumerator.CalcMaxLen;
  45.  
  46. var
  47.    i : word;
  48.  
  49. Begin
  50.    MaxLen := 0;
  51.    for i := 0 to Count - 1 do
  52.       if length ( PString ( At ( i ) )^ ) > MaxLen then
  53.          MaxLen := length ( PString ( At ( i ) )^ );
  54. End;
  55.  
  56. {========================================================================}
  57. { Functions for retrieving the strings within the enumerators            }
  58. {========================================================================}
  59.  
  60. Function SexStr ( Sex : TSex ) : string;
  61.  
  62. Begin
  63.    with Enumerator [ enSex ]^ do
  64.       SexStr := PString ( At ( ord ( Sex ) ) )^;
  65. End;
  66.  
  67. {========================================================================}
  68.  
  69. Function SmokerStr ( Status : TSmoker ) : string;
  70.  
  71. Begin
  72.    with Enumerator [ enSmoker ]^ do
  73.       SmokerStr := PString ( At ( ord ( Status ) ) )^;
  74. End;
  75.  
  76. {========================================================================}
  77.  
  78. Function ProvinceStr ( Province : TProvince ) : string;
  79.  
  80. Begin
  81.    with Enumerator [ enProvince ]^ do
  82.       ProvinceStr := PString ( At ( ord ( Province ) ) )^;
  83. End;
  84.  
  85. {========================================================================}
  86.  
  87. Begin
  88.    { it would probably be better to put these strs into a resource file }
  89.    Enumerator [ enProvince ] := New ( PEnumerator, Init ( 12 ) );
  90.    with Enumerator [ enProvince ]^ do
  91.       begin
  92.       Insert ( NewStr ( 'Nova Scotia' ) );
  93.       Insert ( NewStr ( 'New Brunswick' ) );
  94.       Insert ( NewStr ( 'Newfoundland' ) );
  95.       Insert ( NewStr ( 'Prince Edward Island' ) );
  96.       Insert ( NewStr ( 'Quebec' ) );
  97.       Insert ( NewStr ( 'Ontario' ) );
  98.       Insert ( NewStr ( 'Manitoba' ) );
  99.       Insert ( NewStr ( 'Saskatchewan' ) );
  100.       Insert ( NewStr ( 'Alberta' ) );
  101.       Insert ( NewStr ( 'British Columbia' ) );
  102.       Insert ( NewStr ( 'Yukon' ) );
  103.       Insert ( NewStr ( 'North West Territories' ) );
  104.       CalcMaxLen;
  105.       end;
  106.  
  107.    Enumerator [ enSmoker ] := New ( PEnumerator, Init ( 2 ) );
  108.    with Enumerator [ enSmoker ]^ do
  109.       begin
  110.       Insert ( NewStr ( 'Smoker' ) );
  111.       Insert ( NewStr ( 'Non Smoker' ) );
  112.       CalcMaxLen;
  113.       end;
  114.  
  115.    Enumerator [ enSex ] := New ( PEnumerator, Init ( 2 ) );
  116.    with Enumerator [ enSex ]^ do
  117.       begin
  118.       Insert ( NewStr ( 'Male' ) );
  119.       Insert ( NewStr ( 'Female' ) );
  120.       CalcMaxLen;
  121.       end;
  122. End.
  123.